<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(document).ready(function(){
		// 현재 로그인 한 사용자의 id 를 변수에 저장
		var id="${sessionScope.mvo.id}";
		// 삭제버튼
		$("#deleteBtn").click(function(){
			if(confirm("글을 삭제하시겠습니까?")){
				location.replace("delete.inven?no=${vo.no }&saveFileName=${vo.saveFileName }&category=${vo.category }");
			}
		});
		// 수정버튼
		$("#updateBtn").click(function(){
			if(confirm("글을 수정하시겠습니까?")){
				location.replace("updateView.inven?no=${vo.no }");	
			}
		});
		// 목록버튼
		$("#listBtn").click(function(){
			location.replace("board.inven?category=${vo.category }&contentType=1");
		});
		// 답글버튼
		$("#commentBtn").click(function(){
			if(confirm("답글을 작성하시겠습니까?")){
				location.replace("comment.inven?no=${vo.no }&ref=${vo.ref }&category=${vo.category }&restep=${vo.restep}&relevel=${vo.relevel}");
			}
		});
		// 신고버튼
		$("#reportBtn").click(function(){
			var url="reportMenu.inven?no=${vo.no}&id="+id;
			var pnName="report_window";
			var opt="height=400, width=300, top=200,left=500";
			// 새창을 띄운다.
			window.open(url, pnName, opt);
		});
		
		var picture1 = $("input[name=picture1]").val();
		var picture2 = $("input[name=picture2]").val();
		var picture3 = $("input[name=picture3]").val();

		if(picture1!=undefined){
			if(picture1.indexOf(".jpg")!=-1||picture1.indexOf(".JPG")!=-1){
				$("#pictureView1").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture1+"'>");
			}else if(picture1.indexOf(".png")!=-1||picture1.indexOf(".PNG")!=-1){
				$("#pictureView1").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture1+"'>");
			}else if(picture1.indexOf(".gif")!=-1||picture1.indexOf(".GIF")!=-1){
				$("#pictureView1").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture1+"'>");
			}
		}

		if(picture2!=undefined){
			if(picture2.indexOf(".jpg")!=-1||picture2.indexOf(".JPG")!=-1){
				$("#pictureView2").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture2+"'>");
			}else if(picture2.indexOf(".png")!=-1||picture2.indexOf(".PNG")!=-1){
				$("#pictureView2").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture2+"'>");
			}else if(picture2.indexOf(".gif")!=-1||picture2.indexOf(".GIF")!=-1){
				$("#pictureView2").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture2+"'>");
			}
		}
		
		if(picture3!=undefined){
			if(picture3.indexOf(".jpg")!=-1||picture3.indexOf(".JPG")!=-1){
				$("#pictureView3").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture3+"'>");
			}else if(picture3.indexOf(".png")!=-1||picture3.indexOf(".PNG")!=-1){
				$("#pictureView3").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture3+"'>");
			}else if(picture3.indexOf(".gif")!=-1||picture3.indexOf(".GIF")!=-1){
				$("#pictureView3").html("<img style=' resize: both;max-width: 700px; height: auto;' src='useruploadfile/"+picture3+"'>");
			}
		}

		$(".textArea").autoGrow();
	});//document
</script>
<%-- session 과 vo 를 setting --%>
<c:set value="${requestScope.vo }" var="vo"></c:set>
<c:set value="${sessionScope.mvo }" var="mvo"></c:set>
<c:set value="${requestScope.info }" var="info"></c:set>
<h3 align="center">${vo.category } 게시판</h3>
<hr>
<table>
	<tr>
		<td>No.${vo.no }</td>
		<td><h4>${vo.title }</h4></td>
	</tr>
	<tr>
		<td style="width: 5%;">${vo.id }</td>
		<td style="width: 65%;">&nbsp;</td>
		<td style="width: 30%;">${vo.timePosted } Hits ${vo.hits }</td>
	</tr>
</table>
<hr>
<%----------------------- 파일 다운로드 부분 -----------------------%>
<c:choose>
	<c:when test="${mvo.id==null }">
		<c:forEach items="${saveFileName }" var="name" varStatus="status">
			<input type="hidden" name="picture${status.count}" value="${name }">
			${name }<br>
		</c:forEach> 
	</c:when>
	<c:otherwise>
		<c:forEach items="${saveFileName }" var="name" varStatus="status">
			<input type="hidden" name="picture${status.count}" value="${name }">
			<a href="fileDownload.inven?filename=${name }">${name }</a><br>
		</c:forEach> 
	</c:otherwise>
</c:choose>
<hr>

<%-- 이미지 보여주는 부분 --%>
<div id="pictureView1"></div>
<div id="pictureView2"></div>
<div id="pictureView3"></div>
<textarea class="textArea" cols="97" rows="30" readonly="readonly" style="border-color: white; font-family: NanumGothic; width: 100%; resize:none;">${vo.content }</textarea><br>

<%-- 본인의 꼬릿말 영역 --%>
<table>
	<tr>
		<td width="50%">&nbsp;</td>
		<td width="30%" align="right">
			${info.profile}
		</td>
		<td width="20%">
			<c:choose>
				<c:when test="${info.saveImage!=null }">
					<img height="120" src="userpics/${info.saveImage }">
					<br>
				</c:when>
				<c:otherwise>
					<img src="img/noimage.png" alt="noImage" height="120">
					<br>
				</c:otherwise>
			</c:choose>
		</td>
	</tr>
</table>

		
<%-- 
		게시판 메뉴들(수정, 삭제, 답글쓰기, 목록, 댓글신고)
--%>
<c:choose>
	<c:when test="${vo.id==mvo.id }">
		<input type="button" value="수정" id="updateBtn">
		<input type="button" value="삭제" id="deleteBtn">
	</c:when>
	<c:otherwise>
		<input type="button" value="글 신고" id="reportBtn">
	</c:otherwise>
</c:choose>

<c:if test="${vo.id==mvo.id }">
	
</c:if>
<input type="button" value="목록" id="listBtn">
<%-- 로그인 한 사용자라면 댓글신고 버튼을 보여준다. --%>
<c:if test="${sessionScope.mvo!=null }">
	<input type="button" value="답글쓰기" id="commentBtn">
</c:if>

<!-- 댓글 영역 -->
<c:import url="/WEB-INF/view/board/reply_main.jsp"></c:import>
